package runtime_area

import "jvm/nzpJvm/runtime_area/heap"

// 代表虚拟机栈中的一个栈帧。lower是指向其下面一个栈帧的指针
type Frame struct {
	lower        *Frame
	localVars    LocalVars
	operandStack *OprandStack
	thread       *Thread
	nextPC       int
	method       *heap.Method
}

// 为给定的方法新建一个虚拟机栈的栈帧，用于实现方法调用
func newFrame(thred *Thread, method *heap.Method) *Frame {
	return &Frame{
		thread:       thred,
		method:       method,
		localVars:    newLocalVars(method.MaxLocals()),
		operandStack: newOperandStack(method.MaxStack()),
	}
}

// 回退PC寄存器
func (self *Frame) RevertNextPc() {
	self.nextPC = self.thread.pc
}

// get方法
func (self *Frame) OperandStack() *OprandStack {
	return self.operandStack
}
func (self *Frame) LocalVars() LocalVars {
	return self.localVars
}
func (self *Frame) Lower() *Frame {
	return self.lower
}
func (self *Frame) Thread() *Thread {
	return self.thread
}
func (self *Frame) NextPC() int {
	return self.nextPC
}

func (self *Frame) SetNextPc(pc int) {
	self.nextPC = pc
}

func (self *Frame) Method() *heap.Method {
	return self.method
}
